package cn.tedu.course.role.service.impl;

import cn.tedu.course.role.mapper.RoleMapper;
import cn.tedu.course.role.pojo.dto.RoleQuery;
import cn.tedu.course.role.pojo.dto.RoleSaveParam;
import cn.tedu.course.role.pojo.entity.Role;
import cn.tedu.course.role.pojo.vo.RoleVO;
import cn.tedu.course.role.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleMapper roleMapper;
    @Override
    public List<RoleVO> selectRole(RoleQuery roleQuery) {
        log.debug("查询角色列表业务:roleQuery={}",roleQuery);
        List<RoleVO> list = roleMapper.selectRole(roleQuery);
        return list;
    }

    @Override
    public void saveRole(RoleSaveParam roleSaveParam) {
        log.debug("保存角色业务:roleSaveParam={}",roleSaveParam);
        Role role = new Role();
        BeanUtils.copyProperties(roleSaveParam,role);
        if (role.getId()==null){//新增
            roleMapper.insert(role);
        }else {
            roleMapper.update(role);
        }


    }

    @Override
    public void deleteRole(Long id) {
        log.debug("删除角色业务:id={}",id);
        roleMapper.deleteRole(id);
    }
}
